import Vue from 'vue'
import router from '@/router.js'
import store from '@/store'
import App from './App.vue'
import VueCookie from 'vue-cookie'
import '@/element-ui'
// import '@/icons'                              // api: http://www.iconfont.cn/
import 'element-ui/lib/theme-chalk/index.css'
import '@/assets/scss/index.scss'
import httpRequest from '@/utils/httpRequest'
import cloneDeep from 'lodash/cloneDeep'


Vue.config.productionTip = false

Vue.use(VueCookie)

// 保存整站vuex本地储存初始状态
// window.SITE_CONFIG['storeState'] = cloneDeep(store.state)

Vue.directive('delHtmlTag', {   // 去掉html标签
    bind: function (el, binding, vnode) {
        return binding.value.replace(/<[^>]+>/g, "");
    },
})
/**
 * 把数字转换为大写字母 1 => A, 2 => B
 * @param {number} num 
 */
function numberToUpperCase(num) {
    num = parseInt(num)
    let label = ['A', 'B', 'C', 'D', 'E', 'F', 'G']
    if (num < 64) {
        // return String.fromCharCode(64 + num)
        return  label[num - 1]
    } else { // 多选题
        let _str = ''
        let arr = num.toString(2).slice(1).split('').map(Number)
        arr.map((num, i) => {
            if (num) _str += label[i] + ' ' 
        })
        return _str
    }
    
}
/**
 * 把数字转换为难易度 1 => 简单, 2 => 一般
 * @param {number} num 
 */
function numberToDifficult(num) {
    let arr = ['简单', '一般', '困难']
    return arr[num - 1]
}
/**
 *  去掉html标签
 * @param {string} str 
 */
function delHtmlTag(str) {
    return str.replace(/<[^>]+>/g, "");
}
// 挂载全局
Vue.prototype.$http = httpRequest // ajax请求方法
Vue.prototype.numberToUpperCase = numberToUpperCase
Vue.prototype.numberToDifficult = numberToDifficult
Vue.prototype.delHtmlTag = delHtmlTag

window.SITE_CONFIG = {}
// 保存整站vuex本地储存初始状态
window.SITE_CONFIG['storeState'] = cloneDeep(store.state)
new Vue({
    render: h => h(App),
    router,
    store
}).$mount('#app')
